/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.tnmk.worktime.gui.widget;

import java.awt.event.ActionListener;
import javax.swing.JFrame;
import org.tnmk.worktime.gui.utils.WindowUtils;

/**
 *
 * @author tnmkhoi
 */
public class YesNoDialog extends javax.swing.JPanel implements PopupPanel {

  private PanelPopup popup;

  public YesNoDialog(JFrame parent, String message) {
    initComponents();
    if (message != null) {
      this.jlblMessage.setText(message);
    }
    popup = new PanelPopup(parent, this);
    popup.setLocation(WindowUtils.getCenterX(this), WindowUtils.getCenterY(this));
  }

  public void addYesActionListener(ActionListener yesActionListener) {
    this.jbtnYes.addActionListener(yesActionListener);
  }

  @Override
  public void show() {
    popup.show();
  }

  @Override
  public void hide() {
    popup.hide();
  }

  /**
   * This method is called from within the constructor to initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jLabel1 = new javax.swing.JLabel();
    jlblMessage = new javax.swing.JLabel();
    jbtnYes = new javax.swing.JButton();
    jbtnNo = new javax.swing.JButton();

    setBackground(new java.awt.Color(51, 51, 51));
    setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 2, 2, new java.awt.Color(179, 179, 179)), javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))));

    jLabel1.setFont(new java.awt.Font("Tahoma", 3, 11)); // NOI18N
    jLabel1.setForeground(new java.awt.Color(204, 204, 204));
    jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/Product_Gray_80.png"))); // NOI18N
    jLabel1.setText(" Daily Record");

    jlblMessage.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jlblMessage.setText("Are you sure?");
    jlblMessage.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
    jlblMessage.setOpaque(true);

    jbtnYes.setText("Yes");
    jbtnYes.setOpaque(false);
    jbtnYes.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbtnYesActionPerformed(evt);
      }
    });

    jbtnNo.setText("No");
    jbtnNo.setOpaque(false);
    jbtnNo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbtnNoActionPerformed(evt);
      }
    });

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jlblMessage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
          .addGroup(layout.createSequentialGroup()
            .addGap(94, 94, 94)
            .addComponent(jbtnYes)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jbtnNo)))
        .addGap(0, 89, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabel1)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
        .addComponent(jlblMessage, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(jbtnNo)
          .addComponent(jbtnYes))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
  }// </editor-fold>//GEN-END:initComponents

  private void jbtnNoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnNoActionPerformed
    // TODO add your handling code here:
    this.popup.hide();
  }//GEN-LAST:event_jbtnNoActionPerformed

  private void jbtnYesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnYesActionPerformed
    // TODO add your handling code here:
    this.hide();
  }//GEN-LAST:event_jbtnYesActionPerformed


  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JLabel jLabel1;
  private javax.swing.JButton jbtnNo;
  private javax.swing.JButton jbtnYes;
  protected javax.swing.JLabel jlblMessage;
  // End of variables declaration//GEN-END:variables

  @Override
  public void setPopup(PanelPopup popup) {
    this.popup = popup;
  }
}
